<?php

/**
 * 推荐产品的销售日志管理
 * * @网店运维 (c) 2015-2018 ShopWWI Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.com
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */

defined('ByShopWWI') or exit('Access Invalid!');

class member_saleControl extends BaseMemberControl {

	public function __construct() {
            parent::__construct();
            Language::read('member_predeposit');

	}
      
	public function indexOp() {
             $this->sale_recordlistOp();
             exit;
	}
	

	/**
	 * 产品销售日志列表
	 */
	public function sale_recordlistOp() {

            $model_sale = Model('sale');
            $condition = array();
            $condition['recommend_id'] = $_SESSION['member_id'];
       
            $list = $model_sale ->getSaleRecordList($condition, 20, '*', 'record_id desc');
            
            $record_today_amount=$model_sale->where("recommend_id={$_SESSION['member_id']} AND to_days(date_format(from_UNIXTIME(order_time),'%Y-%m-%d')) = to_days(now())")->sum('sale_amount');
            $record_month_amount=$model_sale->where("recommend_id={$_SESSION['member_id']} AND date_format(from_UNIXTIME(order_time), '%Y%m') = date_format(curdate() , '%Y%m')")->sum('sale_amount');
            $record_today_amount=empty($record_today_amount)?'0.00':ncPriceFormat($record_today_amount);
            $record_month_amount=empty($record_month_amount)?'0.00':ncPriceFormat($record_month_amount);
            Tpl::output('record_today_amount', $record_today_amount);
            Tpl::output('record_month_amount', $record_month_amount);
                        
            //信息输出
            self::profile_menu('log', 'loglist');
            Tpl::output('show_page', $model_sale -> showpage());
            Tpl::output('list', $list);
            Tpl::showpage('member_sale_list');

	}

	


	

	
	/**
	 * 用户中心右边，小导航
	 *
	 * @param string    $menu_type  导航类型
	 * @param string    $menu_key   当前导航的menu_key
	 * @return
	 */

	private function profile_menu($menu_type, $menu_key = '') {

		$menu_array = array( array('menu_key' => 'loglist', 'menu_name' => '销售记录', 'menu_url' => 'index.php?act=member_sale'));

		switch ($menu_type) {
			case 'log' :
			default :
				break;
		}

		Tpl::output('member_menu', $menu_array);
		Tpl::output('menu_key', $menu_key);

	}

}
